﻿using System;
using PropertyExpression.Common;
using PropertyExpression.ControllableQuery;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main()
        {
            var name = Console.ReadLine();

            QExecutor.MaterializeReader(
                command => new {name = command.Param(name), nameHasValue = !string.IsNullOrEmpty(name)},
                p => {
                    var q = new Q(@"
SELECT  ModelId,
        ModelCode
FROM    Model");
                    if (p.nameHasValue)
                        q._(@"
WHERE   ModelCode = ")._(p.name);
                    return q.Query<IModelInfo>();
                });
        }
    }

    public interface IModelInfo
    {
        int ModelId { get; }
        string ModelCode { get; }
    }
}